package com.wejoy.video.middle.station.data.service.alarm.impl;

import com.wejoy.video.middle.station.data.enums.dict.EnumStatus;
import com.wejoy.video.middle.station.data.mapper.alarm.IScreenUserCarmeraConfigTimeMapper;
import com.wejoy.video.middle.station.data.domain.alarm.ScreenUserCarmeraConfigTime;
import com.wejoy.video.middle.station.data.service.alarm.IScreenUserCarmeraConfigTimeService;
import com.wejoy.video.middle.station.data.service.common.IIdWorkerService;
import com.wejoy.video.middle.station.data.util.WJAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户大屏监控记忆配置 
 *
 * @author miracle_j
 * @date 2025年03月28日 18:01:33
 */
@Service
public class ScreenUserCarmeraConfigTimeServiceImpl implements IScreenUserCarmeraConfigTimeService {
    @Autowired
    private IScreenUserCarmeraConfigTimeMapper screenUserCarmeraConfigTimeMapper;
    @Autowired
    private IIdWorkerService idWorkerService;

    @Override
    public void save(ScreenUserCarmeraConfigTime req, String operator) {
        req.setOperator(operator);
        if (null == req.getId()) {
            insertSelective(req);
        } else {
            updateSelectiveById(req);
        }
    }

    @Override
    public int insertSelective(ScreenUserCarmeraConfigTime req) {
        req.setId(idWorkerService.getNextId());
        req.setStatus(EnumStatus.NEW.getCode());
        checkStringLength(req, false);
        return screenUserCarmeraConfigTimeMapper.insertSelective(req);
    }

    @Override
    public int updateSelectiveById(ScreenUserCarmeraConfigTime screenUserCarmeraConfigTime) {
        WJAssert.notNull(screenUserCarmeraConfigTime, "入参对象不能为空");
        WJAssert.notNull(screenUserCarmeraConfigTime.getId(), "id参数错误");
        ScreenUserCarmeraConfigTime where = new ScreenUserCarmeraConfigTime();
        where.setId(screenUserCarmeraConfigTime.getId());
        return screenUserCarmeraConfigTimeMapper.updateSelective(screenUserCarmeraConfigTime, where);
    }

    @Override
    public int getCount(ScreenUserCarmeraConfigTime screenUserCarmeraConfigTime) {
        checkStringLength(screenUserCarmeraConfigTime, true);
        return screenUserCarmeraConfigTimeMapper.getCount(screenUserCarmeraConfigTime);
    }

    @Override
    public ScreenUserCarmeraConfigTime getOneById(Long id) {
        WJAssert.notNull(id, "id参数错误");
        ScreenUserCarmeraConfigTime where = new ScreenUserCarmeraConfigTime();
        where.setId(id);
        return screenUserCarmeraConfigTimeMapper.getOne(where);
    }

    @Override
    public ScreenUserCarmeraConfigTime getOneByPointId(String id) {
        WJAssert.notNull(id, "id参数错误");
        ScreenUserCarmeraConfigTime where = new ScreenUserCarmeraConfigTime();
        where.setPointId(id);
        return screenUserCarmeraConfigTimeMapper.getOne(where);
    }

    @Override
    public List<ScreenUserCarmeraConfigTime> getList(ScreenUserCarmeraConfigTime screenUserCarmeraConfigTime) {
        checkStringLength(screenUserCarmeraConfigTime, true);
        return screenUserCarmeraConfigTimeMapper.getList(screenUserCarmeraConfigTime);
    }

    @Override
    public List<ScreenUserCarmeraConfigTime> getPageList(ScreenUserCarmeraConfigTime screenUserCarmeraConfigTime) {
        checkStringLength(screenUserCarmeraConfigTime, true);
        return screenUserCarmeraConfigTimeMapper.getPageList(screenUserCarmeraConfigTime);
    }

    @Override
    public void audit(Long id, String operator) {
        ScreenUserCarmeraConfigTime req = new ScreenUserCarmeraConfigTime();
        req.setId(id);
        req.setOperator(operator);
        req.setStatus(EnumStatus.AUDIT.getCode());
        updateSelectiveById(req);
    }

    @Override
    public void unaudit(Long id, String operator) {
        ScreenUserCarmeraConfigTime req = new ScreenUserCarmeraConfigTime();
        req.setId(id);
        req.setOperator(operator);
        req.setStatus(EnumStatus.NEW.getCode());
        updateSelectiveById(req);
    }

    @Override
    public void delete(Long id, String operator) {
        ScreenUserCarmeraConfigTime req = new ScreenUserCarmeraConfigTime();
        req.setId(id);
        req.setOperator(operator);
        req.setStatus(EnumStatus.DEL.getCode());
        updateSelectiveById(req);
    }

    /**
     * 参数校验注解默认使用的方法
     */
    private void checkStringLength(ScreenUserCarmeraConfigTime screenUserCarmeraConfigTime, boolean nullAble) {
        WJAssert.notNull(screenUserCarmeraConfigTime, "入参对象不能为空");
        WJAssert.limitMaxLength(screenUserCarmeraConfigTime.getPointId(), true, 65535, "点位ids不合法!");
        WJAssert.limitMaxLength(screenUserCarmeraConfigTime.getOperator(), true, 100, "操作人不合法!");
        WJAssert.limitMaxLength(screenUserCarmeraConfigTime.getRemark(), true, 255, "备注不合法!");
    }
}
